function quickSort(arr, l, r) {
    let head = l, rear = r - 1,key = arr[head]
    while(head < rear) {
        while(head< rear && arr[rear] >= key) {
            rear--
        }
        arr[head] = arr[rear]
        while(head < rear && arr[head] < key) {
            head++
        }
        arr[rear] = arr[head]
    }
    arr[head] = key
    if(head > l) {
        arr = quickSort(arr, l, head)
    }
    if(head + 1 < r) {
        arr = quickSort(arr, head + 1, r)
    }
    return arr
}
let arr = [9, 4, 6, 2, 1, 1, 8]
console.log(quickSort(arr, 0, arr.length));